<?php
/**
 * 网页抢楼模块定义
 *
 * @author junsion
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');
define('OD_ROOT', IA_ROOT . '/addons/junsion_netlottery');
class Junsion_netlotteryModule extends WeModule {

	public function settingsDisplay($settings) {
		global $_W, $_GPC;
	//微信支付商户功能参数设置 
		if(checksubmit()) {
			load()->func('file');

			mkdirs(OD_ROOT . '/cert');

			$r = true;

			if(!empty($_GPC['cert'])) {

				$ret = file_put_contents(OD_ROOT . "/cert/".md5("apiclient_{$_W['uniacid']}cert").".pem", trim($_GPC['cert']));

				$r = $r && $ret;

			}

			if(!empty($_GPC['key'])) {

				$ret = file_put_contents(OD_ROOT . "/cert/".md5("apiclient_{$_W['uniacid']}key").".pem", trim($_GPC['key']));

				$r = $r && $ret;

			}

			if(!empty($_GPC['ca'])) {

				$ret = file_put_contents(OD_ROOT . "/cert/".md5("root{$_W['uniacid']}ca").".pem", trim($_GPC['ca']));

				$r = $r && $ret;

			}

			if(!$r) {

				message('证书保存失败, 请保证 /addons/'.$this->modulename.'/cert/ 目录可写');

			}

			$dat['api'] = array(

								'mchid'=>$_GPC['mchid'],

								'password'=>$_GPC['password'],

								'ip'=>$_GPC['ip'],

								'appid'=>$_GPC['appid'],

						  );

			$s = array_elements(array('title', 'provider', 'wish', 'remark'), $_GPC);

			$dat['redpacket'] = $s;

			if($this->saveSettings($dat)){

				message('保存成功','refresh');

			}

		}

		$config = $settings['api'];

		$red = $settings['redpacket'];

		if(empty($config['ip'])) {

			$config['ip'] = $_SERVER['SERVER_ADDR'];

		}

		$setting = uni_setting($_W['uniacid'], array('oauth'));
		
		$oauth = $setting['oauth'];
		
		if (!empty($oauth) && !empty($oauth['status']) && !empty($oauth['account'])) {
		
			$auth = account_fetch($oauth['account']);
		
		}
		
		//这里来展示设置项表单
		include $this->template('setting');
	}

}